//
//  SyncHandlerGetAlumnos.m
//  MasterUabApp
//
//  Created by Alumne on 13/10/13.
//  Copyright (c) 2013 Owlab. All rights reserved.
//


//----IMPORTS-->
#import "SyncHandlerGetAlumnos.h"
#import "EConsts.h"
#import "ECommon.h"
#import "Alumno.h"
//<-------------

@implementation SyncHandlerGetAlumnos


- (int) getType
{
    return SYNC_HANDLER_TYPE_NONE;
}

- (NSString*) getMethod
{
    return @"services.php?listaAlumnos";
}

- (void) fillRequestParams:(NSMutableDictionary*)data
{
    [super fillRequestParams:data];
}

- (BOOL) processJSON:(id)data;
{
    BOOL ok = YES;
    
    AlumnoArray *alumnoArray = (AlumnoArray*)self.delegate;
    [alumnoArray.arrayAlumnos removeAllObjects];
   
    NSArray*arr = (NSArray*)data;
    
    NSDictionary *objData;
    for(int i = 0; i<arr.count && ok && !self.cancelled;i++)
    {
        objData = [arr objectAtIndex:i];
        Alumno *alumno = [[Alumno alloc]init];
        alumno.AlumnoId         = [self stringFromJSON:[objData objectForKey:@"AlumnoId"]];
        alumno.AlumnoNombre     = [self stringFromJSON:[objData objectForKey:@"AlumnoNombre"]];
        alumno.AlumnoApellidos  = [self stringFromJSON:[objData objectForKey:@"AlumnoApellidos"]];
        alumno.AlumnoNIF        = [self stringFromJSON:[objData objectForKey:@"AlumnoNIF"]];
        alumno.AlumnoFoto       = [self stringFromJSON:[objData objectForKey:@"AlumnoFoto"]];

        [alumnoArray.arrayAlumnos addObject:alumno];
    }

    [self syncDone:YES object:alumnoArray];
    
    return ok;
}

@end